/** \file lcd_menu.c
	\brief File contains definitions of functions which are writing and reading messages from SD/MMC card.
	\author Tomasz Kasprzycki
	\date 20-06-2009
*/
#include <avr/pgmspace.h>
#include "fat16.h"
#include "fat16_config.h"
#include "partition.h"
#include "sd_raw.h"
#include "sd_raw_config.h"

/** \def LCD_COLS
	\brief Size of message which are saveing on SD/MMC card
*/
#define MessageSize 17

/** \struct sdcard_file_struct
	\brief Contains information about file system and data structure 
*/
struct sdcard_file_struct {
	struct fat16_fs_struct* fs;
	struct fat16_dir_struct* dd;
	char *file;
};

/** \fn vWriteToFile(int32_t offset_value, struct fat16_fs_struct* fs, struct fat16_dir_struct* dd, char* buf);
	\brief Write \a messages to text file in SD/MMC card. 
	\param fd1 The file handle of the file to which to write.
	\param fs The filesystem on which the file to open lies.
	\param dd The directory descriptor to write on.
	\param buf The buffer from which to read the data to be written.
	\param offset_value The function writes the new absolute offset to this location before it returns.
*/
void vWriteToFile(int32_t offset_value, struct fat16_fs_struct* fs, struct fat16_dir_struct* dd, char* buf);

/** \fn vReadFile(struct fat16_fs_struct* fs, struct fat16_dir_struct* dd,unsigned char ucLineNumber,uint8_t cLineDestination[]);
	\brief Write \a messages to text file in SD/MMC card. 
	\param fd1 The file handle of the file to which to write.
	\param fs The filesystem on which the file to open lies.
	\param dd The directory descriptor to read from.
	\param ucLineNumber Define which line number we should read. 
	\param cLineDestination Destination array where we write strings readed from SD/MMC card
*/
void  vReadFile(struct fat16_fs_struct* fs, struct fat16_dir_struct* dd,unsigned char ucLineNumber,uint8_t cLineDestination[]);

/** \fn struct fat16_file_struct* open_file_in_dir(struct fat16_fs_struct* fs, struct fat16_dir_struct* dd, const char* name)
	\brief Open file from specify directory located on SD/MMC card. 
	\param fs The filesystem on which the file to open lies.
	\param dd The directory descriptor to read from.
	\param name Name of the file to open.
*/
struct fat16_file_struct* open_file_in_dir(struct fat16_fs_struct* fs, struct fat16_dir_struct* dd, const char* name);

/** \fn uint8_t find_file_in_dir(struct fat16_fs_struct* fs, struct fat16_dir_struct* dd, const char* name, struct fat16_dir_entry_struct* dir_entry)
	\brief Search file from specify directory located on SD/MMC card. 
	\param fs The filesystem on which the file to open lies.
	\param dd The directory descriptor to read from.
	\param name Name of the file to open.
	\param dir_entry The directory entry which stands for the directory to open.
*/
uint8_t find_file_in_dir(struct fat16_fs_struct* fs, struct fat16_dir_struct* dd, const char* name, struct fat16_dir_entry_struct* dir_entry);

/** \fn uint64_t SDcard_GetNumberOfLines(void);
	\brief Get number of lines in text file located on SD/MMC card. 
*/
uint64_t SDcard_GetNumberOfLines(void);

/** \fn void SDcard_ReadLine(uint64_t uiLineNumber, uint8_t cLineDestination[]);
	\brief Read only specify line in text file located on SD/MMC card.
	\param uiLineNumber Number of line in text file.
	\param cLineDestination Destination array where we write strings readed from SD/MMC card
*/
void SDcard_ReadLine(uint64_t uiLineNumber, uint8_t cLineDestination[]);

/** \fn SDcard_WriteMsg( char* buff);
	\brief Write text into terx file located on SD/MMC card. 
	\param buf The buffer from which to read the data to be written.
*/
void SDcard_WriteMsg( char* buff);




